package ua.edu.test.menu;

import android.app.Activity;
import android.os.Bundle;
import android.text.util.Linkify;
import android.util.Patterns;
import android.widget.TextView;
import ua.edu.test.R;

public class BankInfo extends Activity {
    private TextView tvAddress;
    private TextView tvTel;
    private TextView tvSite;
    int i;
    String[] banks_address;
    String[] banks_tel;
    String[] banks_site;
    private final static int MY_PHONE_NUMBER_MINIMUM_DIGITS = 3;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bank);
        Bundle extras = getIntent().getExtras();
        i = extras.getInt("selectedBank");
        tvAddress = (TextView) findViewById(R.id.tvAddress);
        banks_address = getResources().getStringArray(R.array.banks_address);
        tvAddress.setText(banks_address[i]);
        tvTel = (TextView) findViewById(R.id.tvTel);
        banks_tel = getResources().getStringArray(R.array.banks_tel);
        tvTel.setText(banks_tel[i]);
        Linkify.addLinks(tvTel, Patterns.PHONE, "tel:", new Linkify.MatchFilter() {
            public final boolean acceptMatch(CharSequence s, int start, int end) {
                int digitCount = 0;

                for (int i = start; i < end; i++) {
                    if (Character.isDigit(s.charAt(i))) {
                        digitCount++;
                        if (digitCount >= MY_PHONE_NUMBER_MINIMUM_DIGITS) {
                            return true;
                        }
                    }
                }
                return false;
            }
        }, Linkify.sPhoneNumberTransformFilter);

        tvSite = (TextView) findViewById(R.id.tvSite);
        banks_site = getResources().getStringArray(R.array.banks_site);
        tvSite.setText(banks_site[i]);
    }

}
